package com.hzy.fivepalace.wx.controller.api;

import com.hzy.fivepalace.common.util.JacksonUtil;
import com.hzy.fivepalace.db.vo.wx.WxConfirmOrderQueryVo;
import com.hzy.fivepalace.wx.annotation.LoginUser;
import com.hzy.fivepalace.wx.controller.base.BaseController;
import com.hzy.fivepalace.wx.service.WxVipService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/wx/user")
@Validated
@Api(tags = "会员服务")
public class WxVipController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(WxVipController.class);


    @Resource
    private WxVipService wxVipService;


    /**
     * 获取会员配置列表
     * @return
     */
    @GetMapping("/getVipConfigList")
    @ApiOperation(value = "获取会员配置列表")
    public Object getVipConfigList() {

        return wxVipService.getVipConfigList();
    }

    /**
     * 获取vip配置详情
     *
     * @param userId
     * @param vipId
     * @return
     */
    @GetMapping("/getVipConfigDetail")
    @ApiOperation(value = "获取vip配置详情")
    public Object getVipConfigDetail(@LoginUser(login = false) @ApiParam(hidden = true) Integer userId,
                         @ApiParam(value = "会员ID") @NotNull Long vipId) {
        return wxVipService.getVipConfigDetail(userId, vipId);
    }

    /**
     * 购买会员
     * @param userId
     * @param body
     * @return
     */
    @PostMapping("/byVip")
    @ApiOperation(value = "购买会员")
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    public Object byVip(@LoginUser @ApiParam(hidden = true) Integer userId,   @ApiParam(value = "{vipId:'会员id'}") @RequestBody String body) {
        Long vipId= JacksonUtil.parseObject(body, "vipId",Long.class);
        return wxVipService.byVip(userId, vipId);
    }
}
